include ../mk.cfg

OUTPUT_DIR= output
OUTPUT_BIN= $(OUTPUT_DIR)/bin
OUTPUT_LIB= $(OUTPUT_DIR)/lib

MK_OUT= 
ifneq ($(OUTPUT_DIR),$(wildcard $(OUTPUT_DIR)))
	MK_OUT= mkdir $(OUTPUT_DIR) && mkdir $(OUTPUT_BIN) && mkdir $(OUTPUT_LIB)
else
    ifneq ($(OUTPUT_BIN),$(wildcard $(OUTPUT_BIN)))
        ifneq ($(OUTPUT_LIB),$(wildcard $(OUTPUT_LIB)))
			MK_OUT= mkdir $(OUTPUT_BIN) && mkdir $(OUTPUT_LIB)
        else
			MK_OUT= mkdir $(OUTPUT_BIN)
        endif
    else
        ifneq ($(OUTPUT_LIB),$(wildcard $(OUTPUT_LIB)))
			MK_OUT= mkdir $(OUTPUT_LIB)
        endif
    endif
endif

PLATFORM= linux
ifeq ($(PLAT),win)
	PLATFORM= mingw
	LFS_MKFILE= Makefile.win
else
	LFS_MKFILE= Makefile.linux
endif

all: lua lfs

lua:
	cd lua-5.3.5 && \
	$(MAKE) $(PLATFORM)
	$(MK_OUT)
	cp lua-5.3.5/src/lua.exe lua-5.3.5/src/luac.exe lua-5.3.5/src/lua53.dll $(OUTPUT_BIN)
	cp lua-5.3.5/src/lua.o lua-5.3.5/src/lua53.dll $(OUTPUT_LIB)

lfs:
	cd luafilesystem && \
	cp $(LFS_MKFILE) Makefile && \
	$(MAKE) lib
	cp luafilesystem/src/lfs.dll $(OUTPUT_BIN)

clean:
	cd lua-5.3.5 && \
	$(MAKE) clean
	cd luafilesystem && \
	cp $(LFS_MKFILE) Makefile && \
	$(MAKE) clean
	rm -rf output












